﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
//5-1-A-spx
public partial class login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string userid;
        userid = TextBox1.Text;

        //打开数据库
        SqlConnection con = DB.createConnection();
        con.Open();

        string sql = "select count(*) as iCount from users where userID='" + userid + "' ";
        SqlCommand com = new SqlCommand(sql, con);
        SqlDataReader Dr1;
        Dr1 = com.ExecuteReader();
        Dr1.Read();
        string Count = Dr1["finish1"].ToString();
        //Label.Text = Dr1["finish1"].ToString();
        Dr1.Close();
        if (Count != "0")
        {
            string sql2 = "select count(*) as iCount from users where userID='" + userid + "' and finish=0  ";
            SqlCommand com2 = new SqlCommand(sql2, con);

            SqlDataReader Dr2;
            Dr2 = com2.ExecuteReader();
            Dr2.Read();
            string Count2 = Dr2["iCount"].ToString();
            Dr2.Close();

            if (Count2 != "0")
            {
                string sql3 = "update users set finish=finish+1 where userID='" + userid + "'";
                SqlCommand com3 = new SqlCommand(sql3, con);
                com3.ExecuteNonQuery();
                string url;
                url = "showindex.aspx?userID=" + userid;
               //Response.Redirect(url);
               // this.RegisterClientScriptBlock("js", "<script>alert('  登陆成功！  ');window.location.href='index.aspx'</script>");
               Response.Write("<script>window.location.href='vote.aspx'</script>");
                //  public void Alert (string message);
            }
            else
            {
               Response.Write("<script>alert('  您只能填一次问卷，谢谢！ 进入结果页面！  ');window.location.href='showResult.aspx'</script>");
                // Response.Redirect("showResult.aspx");
            }
        }
        else
            this.RegisterClientScriptBlock("js", "<script>alert('  对不起，您没有权限！进入结果页面！  ');window.location.href='showResult.aspx'</script>");

        con.Close();
    }
}
